#ifndef _RESOURCEFILE_H_
#define _RESOURCEFILE_H_

#include "vfs/vfs.h"
#include <string>
#include "tracked.h"
#include "num/named_set.h"

namespace res
{
class ResMan;
class ResourceFile : public Tracked
{
public:
	enum	RES_TYPES
	{
		RES_SURFACE,
		RES_AUDIO,
		RES_UNKNOWN
	};
	enum	RES_STATUS
	{
		RS_NEW,			// initial state
		RS_LOADING,			// pending loading
		RS_CACHED,			// successfully loaded, but not used
		RS_READY,			// loaded and ready to use
		RS_RELEASED,		// released
		RS_FAILED			// failed to create
	};

	/**
	 * @brief:	Start the loading process. Note that there's no guarantee it'll be ready \n
	 *			immediatly, since this is implementation specific.
	 * @param:	_File		Name of file to load (will be loaded from VFS)
	 */
	bool					Load(const std::string& _File);
	void					FromMemory(unsigned char* pData, unsigned int	Size);
	/// check state
	inline RES_STATUS		GetState() const { return m_State; };
	inline unsigned int		GetID() const { return m_ID; };
	/// reference counting
	inline void				IncrementRef() { m_RefCount++; };
	inline void				DecrementRef() { m_RefCount--; };

	const std::string&		GetName()		{ return m_Name; };
	const std::string&		GetPath()		{ return m_Path; };
	const std::string&		GetExtension()	{ return m_Extension; };
	RES_TYPES				GetFileType() const { return m_FileType; };

	/// TODO: Codewarrior doesn't like simple friend semantics. Moved out for now
	/// should only be created through the resource manager
	ResourceFile();
	/// should only be deleted through the resource manager
	virtual ~ResourceFile();
	/// create resource as a hardware specific format
	virtual void			InitializeResource() = 0;
	/// remove all data from RAM, but keep track of origin so that it can be reaquired
	virtual void			ReleaseResource() = 0;



protected:

	/// load resource into RAM.
	virtual	void			CacheResource();


	/// file changed on disk
	virtual	void		OnFileChangeNotify(const std::string& _Filename) 
	{	
		ReleaseResource();
		CacheResource();
	};


	/// ResourceFile name
	std::string		m_Name;
	/// ResourceFile path
	std::string		m_Path;
	/// extension type
	std::string		m_Extension;
	/// ResourceFile ID
	unsigned int	m_ID;
	/// What type of file is this?
	RES_TYPES		m_FileType;
	/// ResourceFile size (bytes)
	unsigned int	m_Size;
	/// ResourceFile State
	RES_STATUS		m_State;
	/// Number of references 
	int				m_RefCount;
	/// Last accessed
	float			m_LastAccessed;
	/// data loaded from the vfs.. be carefull not to double-use this
	vfs::LoadedBlock	m_Data;


};
} // namespace res

#endif // _RESOURCE_H_